#########################################################################################
#
# Copyright (C) 2008  
# Authors: Aljosa Osep (aljosa.osep@gmail.com), Jernej Kranjec (jernej.kranjec@gmail.com)
# From Faculty of Electrical Engineering and Computer Science, Maribor, Slovenia
# Done at School of Technology, Seinajoki, Finland
# Under mentor Kimmo Salmenjoki (kimmo.salmenjoki@seamk.fi)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################################

import sys
from osv import fields, osv
from time import strftime
from modules import commModule


#----------------------------------------------------------
# Console for RFID
#----------------------------------------------------------

class rscd_demo_console(osv.osv):
	_name = "rscd_demo.console"
	_description = "Console"
	_columns = {
		'name': fields.char('Device Name', size=64, required=True),
		'command': fields.char('Command', size=64),
		'answare': fields.text('Answare'),
	}
	_defaults = {
		'answare': lambda *a: '',
	}

	def button_execute(self, cr, uid, ids, context={}):
			     
		self.communicator = commModule.Communicator(False)
		
		for com in self.read(cr, uid, ids, ['command','answare'], context):
			self.communicator.sendData(com['command'] + '\r\n')
			ii = self.communicator.retriveData()
			cc =  com['answare'] + strftime("%Y-%m-%d %H:%M:%S") + ':\n' + com['command'] + '\n' + ii + '\n'
			self.write(cr, uid, ids, {'answare': cc})
			self.write(cr, uid, ids, {'command': ""})
			
		return True

	def button_clear(self, cr, uid, ids, context={}):
		self.write(cr, uid, ids, {'answare': ""})
		return True
	
rscd_demo_console()
